﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

using PRET.ReportDataDefine.UIData;
using PRET.DBAdapter;

namespace PRET.PRETWebService
{
    // 注意: 使用“重构”菜单上的“重命名”命令，可以同时更改代码、svc 和配置文件中的类名“PRETService”。
    // 注意: 为了启动 WCF 测试客户端以测试此服务，请在解决方案资源管理器中选择 PRETService.svc 或 PRETService.svc.cs，然后开始调试。
    public class PRETWebServiceJSON : IPRETWebServiceJSON
    {
        private static ServiceAdapter adapter = null;

        public PRETWebServiceJSON()
        {
            if (adapter == null)
                adapter = new ServiceAdapter();
        }

        public List<ProductionReportSummaryForJSON> GetProLineStatus()
        {
            return adapter.GetProLineStatus();
        }

        public List<ProductiveTaskReportTV> GetProductiveTask()
        {
            return adapter.GetProductiveTaskReportForTV();
        }

        //public List<ProductiveTaskReport> GetProductiveTask()
        //{
        //    return adapter.GetProductiveTaskReport();
        //}

        public List<ProductionLineEfficiencyReport> GetProductionLineEfficiency(string year)
        {
            List<ProductionLineEfficiencyReport> retList = new List<ProductionLineEfficiencyReport>();
            //DateTime startYear;
            //year = string.Format("{0}-01-01 00:00:00", year);
            //if (DateTime.TryParse(year, out startYear))
            //    retList = adapter.GetProductionLineEfficiencyReportForTV(startYear);
            retList = adapter.GetProductionLineEfficiencyReportForTV(DateTime.Now);
            return retList;
        }

        public List<TeamEfficiencyReport> GetTeamEfficiency(string year)
        {
            List<TeamEfficiencyReport> retList = new List<TeamEfficiencyReport>();
            DateTime startYear;
            //year = string.Format("{0}-01-01 00:00:00", year);
            year = string.Format("{0}-01-01 00:00:00", DateTime.Now.Year);
            if (DateTime.TryParse(year, out startYear))
            {
                //retList = adapter.GetTeamEfficiencyReportForTV(startYear);
                retList = adapter.GetTeamEfficiencyReport2(startYear);
            }
            return retList;
        }

        //public TVControlInfo ShowMessage()
        public String ShowMessage()
        {
            TVControlInfo info = adapter.ShowMessage();
            if (info != null)
                return info.Message;
            return "";
        }

        public ShowConfig GetShowConfig()
        {
            return adapter.GetShowConfig();
        }
    }
}
